package cn.com.controller.administrator;

import cn.com.dao.TaskDao;
import cn.com.entity.ClassTimetable;
import cn.com.entity.Clazz;
import cn.com.entity.Course;
import cn.com.entity.Teacher;
import cn.com.tool.Jdbc;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project:Academic - TaskController
 *
 * @author 黄俊玮 On Administrator
 * @version 1.0
 * @DataTime 2024/6/14 08:51:20
 * @since 1.8
 */
public class TaskController {
    private TaskDao taskDao = new TaskDao();
    public void show(HttpServletRequest request , HttpServletResponse response) throws IOException, ServletException{

        List<ClassTimetable> list = taskDao.getClassTimetableList();
        List<Teacher> tea = taskDao.getTeacherList();
        List<Clazz> cla = taskDao.getClazzList();
        List<Course> cou = taskDao.getCourseList();
        request.setAttribute("tea" ,tea);
        request.setAttribute("cla" ,cla);
        request.setAttribute("cou" ,cou);

        request.getSession().setAttribute("task",list);
        request.getRequestDispatcher("/WEB-INF/jsp/manager/task/show.jsp").forward(request,response);
    }
    public void delete(HttpServletRequest request , HttpServletResponse response) throws  IOException,ServletException{
        int id = Integer.parseInt(request.getParameter("id"));
        taskDao.delete(id);
        request.getRequestDispatcher("/Administrator/task.do").forward(request,response);
    }
    public void add(HttpServletRequest request, HttpServletResponse response) throws  IOException,ServletException{
        String teacher = request.getParameter("teacher");
        String aClass = request.getParameter("clazz");
        String courses = request.getParameter("courses");

        boolean k = taskDao.add(teacher,aClass,courses);
        if (k){
            request.getRequestDispatcher("/Administrator/task.do").forward(request,response);
            return;
        }
        request.setAttribute("err","课程重复！！！");
        request.getRequestDispatcher("/Administrator/task.do").forward(request,response);
    }
}
